package com.buddy.webmagic.configuration;

import com.buddy.webmagic.filter.ViewFilter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableAutoConfiguration
@ComponentScan("com.buddy.webmagic")
public class StaticConfigure extends WebMvcConfigurerAdapter{

    public void addViewControllers( ViewControllerRegistry registry ) {
        registry.addViewController( "/" ).setViewName( "forward:/html/dataCollect/index.html" );
        super.addViewControllers( registry );
    }
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/*.html").addResourceLocations("classpath:/static/html/dataCollect/");
    }
	@Bean
	public FilterRegistrationBean filterRegistrationBean(){
		 FilterRegistrationBean filterRegist = new FilterRegistrationBean();
		 ViewFilter viewFilter = new ViewFilter();
	     filterRegist.setFilter(viewFilter);
	     filterRegist.addInitParameter("excludeType", "js,css,png,jpg,gif,jpeg");
	     filterRegist.addUrlPatterns("/*");
	     return filterRegist;
	}
}
